package com.interfaces;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.entity.TaskRecord;

/**   
* @Title: TaskRecordDao.java 
* @Package com.interfaces 
* @author 孙梦楠 
* @date 2017年9月5日 下午3:05:26 
* @version V1.0.0   
*/

public interface TaskRecordDao extends JpaRepository<TaskRecord, Integer>{
	
	//更新执行结论  传入 taskid 和time 修改endtime  successnum  successrate
	@Transactional
	@Modifying
	@Query("update TaskRecord tr set tr.endtime = ?4 ,tr.successnum=?5 ,tr.successrate=?6 ,tr.totalnum=?7 where tr.taskid=?1 AND tr.begintime=?2 AND tr.terminaladdress=?3") 
	int updateTaskRecordItem(Integer taskid,String time,String terminaladdress,String endtime,String successnum,String successrate,String totalnum);
	
	List<TaskRecord> findByTaskid(Integer taskid);
	
	//执行结论列表
	
	@Query(value="SELECT tr FROM TaskRecord tr WHERE (tr.taskid=?1 OR ?1 IS NULL) AND (tr.time=?2 OR ?2 IS NULL) "
			+ "AND (tr.begintime > ?3 OR  ?3 IS NULL) AND (tr.begintime < ?4 OR ?4 IS NULL) "
			+ "AND (tr.taskid IN (SELECT t.taskid FROM Task t WHERE t.taskorg=?5 AND t.tasktype=?6))") 
	public List<TaskRecord> listTaskRecord(Integer taskid,String time,String begintime,String endtime,Integer taskorg,String tasktype);

}
